package com.andnnl.file;

import com.andnnl.fileanalysis.AnalysisListener;
import com.andnnl.fileanalysis.AnalysisParam;
import com.andnnl.fileanalysis.CountListener;
import com.andnnl.fileanalysis.FileAnalysisManage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ReadExcelTest {
    private static final Logger logger = LoggerFactory.getLogger(ReadExcelTest.class);

    public static void main(String[] args) {
        final ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {
            executorService.submit(()->{
                test1();
            });
        }
//        test1();
//        testZip();
    }

    private static void testZip() {
        File file = new File("E:\\号码优化\\YhMobile_500041可优化名单2.zip");
        AnalysisListener listener = rowList -> {
            logger.info("batch size:" + rowList.size());
            for (List<String> strings : rowList) {
//                    logger.info(strings.toString());
            }
        };
        AnalysisParam param = AnalysisParam.build()
                .setBatchSize(100000)//读到一批后调用一次invokeBatch
                .setDelHeadRows(1)//删除头部行数，空行不算
//                .setExt("txt")//指定解析的文件格式
//                .setCharset("UTF-8")//指定解析的文件编码
//                .setCharset("GBK")//指定解析的文件编码
//                .setSplitLimit(2)//txt分割2列
                .setMaxRow(0);//限制读取行数,0:不限制
                CountListener countlistener=new CountListener();
        FileAnalysisManage.analysisZip(file, countlistener, param);
        logger.info("listener.count:"+countlistener.getCount());
        FileAnalysisManage.analysisZip(file, listener, param);
    }

    private static void test1() {
        System.out.println(Thread.currentThread().getName());
        //        File file=new File("/Users/workspace/file-analysis/src/test/java/com/andnnl/test/test1.txt");
//        File file=new File("C:\\Users\\andnn\\Desktop\\1w_mobileGw.xls");
//        File file=new File("D:\\python-workspace\\Test1\\68601_ls_random_2.xlsx");
//        File file=new File("D:\\python-workspace\\Test1\\68601_5.csv");
//        File file=new File("E:\\号码优化\\YhMobile_交警可优化名单.csv");
//        File file = new File("E:\\号码优化\\all_content.csv");
        File file = new File("C:\\Users\\Administrator\\Desktop\\gwResendDefault.xlsx");
        AnalysisListener listener = rowList -> {
            logger.info("batch size:" + rowList.size());
            for (List<String> strings : rowList) {
//                    logger.info(strings.toString());
            }
        };
        AnalysisParam param = AnalysisParam.build()
                .setBatchSize(200)//读到一批后调用一次invokeBatch
                .setDelHeadRows(1)//删除头部行数，空行不算
//                .setExt("txt")//指定解析的文件格式
//                .setCharset("UTF-8")//指定解析的文件编码
//                .setCharset("GBK")//指定解析的文件编码
                .setSplitLimit(2)//txt分割2列
                .setMaxRow(0);//限制读取行数,0:不限制
//        CountListener countlistener=new CountListener();
//        FileAnalysisManage.analysis(file, countlistener, param);
//        logger.info("listener.count:"+countlistener.getCount());
        FileAnalysisManage.analysis(file, listener, param);
        System.out.println("finish "+Thread.currentThread().getName());
    }
}
